package org.andhy.formeasy.core;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

public class Result {
	public boolean success = true;
	public Map<String, Set<String>> messages = new HashMap<String, Set<String>>();

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean isSuccess) {
		success = isSuccess;
	}

	public void addSingleMessage(String fildKey, String message) {
		if (fildKey == null || message == null)
			return;
		Set<String> msgset = messages.get(fildKey);
		if (null == msgset) {
			msgset = new HashSet<String>();
			messages.put(fildKey, msgset);
		}
		msgset.add(message);
	}
	
	public void addMesaageSet(String fildKey,Set<String> msgset){
		if (fildKey == null || msgset == null)
			return;
		Set<String> msgsetold = messages.get(fildKey);
		if (null == msgsetold) {
			messages.put(fildKey, msgset);
		}else{
			msgsetold.addAll(msgset);
		}
	}
	
	public Map<String,Set<String>> getAllMessage(){
		return messages;
	}
	
	public Map<String,String> getSingleMessage(){
		Map<String,String> singlemsg = new HashMap<String,String>();
	    for(Entry<String, Set<String>> filedEntry : messages.entrySet()){
	    	String filed = filedEntry.getKey();
	    	Set<String> valueSet = filedEntry.getValue();
	       	for(String value : valueSet){
	    		singlemsg.put(filed, value);
	    		break ;
	    	}
	    }
		return singlemsg;
		
	}
}
